﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using QuanLyDatVe.DataAccessLayer;
using System.Data.SqlClient;
using System.Data;
using QLNHang.DTO;

namespace QLNHang.DAO
{
    class VeDAO
    {

        private ConnectDatabase cn = new ConnectDatabase();
        DBNull dbNULL = DBNull.Value;
        public int ThemVe(VeDTO veDTO)
        {
            cn.OpenDatabase();
            SqlCommand cmd = new SqlCommand("sp_ThemVe", cn.SqlConnect);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@doiTuong", string.IsNullOrEmpty(veDTO.DoiTuong) ? dbNULL : (object)veDTO.DoiTuong);
            cmd.Parameters.AddWithValue("@thoiGian", string.IsNullOrEmpty(veDTO.ThoiGian) ? dbNULL : (object)veDTO.ThoiGian);
            cmd.Parameters.AddWithValue("@loaiVe", string.IsNullOrEmpty(veDTO.LoaiVe) ? dbNULL : (object)veDTO.LoaiVe);
            cmd.Parameters.AddWithValue("@giaVe", string.IsNullOrEmpty(veDTO.GiaVe) ? dbNULL : (object)veDTO.GiaVe );
           

            int success = cmd.ExecuteNonQuery();
            cn.CloseDatabase();
            return success;
        }
        public int SuaVe(VeDTO veDTO)
        {
            cn.OpenDatabase();
            SqlCommand cmd = new SqlCommand("sp_SuaVe", cn.SqlConnect);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@maVe", string.IsNullOrEmpty(veDTO.MaVe) ? dbNULL : (object)veDTO.MaVe);
            cmd.Parameters.AddWithValue("@doiTuong", string.IsNullOrEmpty(veDTO.DoiTuong) ? dbNULL : (object)veDTO.DoiTuong);
            cmd.Parameters.AddWithValue("@thoiGian", string.IsNullOrEmpty(veDTO.ThoiGian) ? dbNULL : (object)veDTO.ThoiGian);
            cmd.Parameters.AddWithValue("@loaiVe", string.IsNullOrEmpty(veDTO.LoaiVe) ? dbNULL : (object)veDTO.LoaiVe);
            cmd.Parameters.AddWithValue("@giaVe", string.IsNullOrEmpty(veDTO.GiaVe) ? dbNULL : (object)veDTO.GiaVe);

            int success = cmd.ExecuteNonQuery();
            cn.CloseDatabase();
            return success;
        }
        public DataTable XemDanhSachVe()
        {
            var dt = new DataTable();
            cn.OpenDatabase();
            SqlCommand cmd = new SqlCommand("sp_XemDanhSachVe", cn.SqlConnect);
            cmd.CommandType = CommandType.StoredProcedure;
            var sda = new SqlDataAdapter(cmd);
            sda.Fill(dt);
            cn.CloseDatabase();
            return dt;
        }
    }
}
